package com.huadao.cart_ccs.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.widget.Toast;

import com.daolion.base.utils.StringUtils;
import com.huadao.cart_ccs.Constant;
import com.huadao.cart_ccs.R;

/*
    ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ 
       Author   :  lixiaodaoaaa
       Date     :  2020-03-09
       Time     :  14:44
    ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
 */
public class SerialPortSettingUtils {

    public static boolean isSettingValid(Context context, boolean isNeedToast) {
        SharedPreferences sp = context.getSharedPreferences(Constant.PREFERCENCE_FILE_NAME, Context.MODE_PRIVATE);
        String device = sp.getString("DEVICE", "");
        if (StringUtils.isEmpty(device)) {
            String selectDeviceTips = context.getResources().getString(R.string.select_device_tips);
            Toast.makeText(context, selectDeviceTips, Toast.LENGTH_SHORT).show();
            return false;
        }
        if (Integer.decode(sp.getString("BAUDRATE", "-1")) == -1) {
            String selectBaudaurateTips = context.getResources().getString(R.string.select_baudurate_tips);
            Toast.makeText(context, selectBaudaurateTips, Toast.LENGTH_SHORT).show();
            return false;
        }
        return true;
    }
}
